home *** CD-ROM | disk | FTP | other *** search
/ 3D GFX / 3D GFX.iso / amiutils / i_l / irit5 / cagd_lib / cagdedit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-31  |  5.1 KB  |  121 lines

  1. /******************************************************************************
  2. * CagdEdit.c - Editing tools of surfaces and Curves.                  *
  3. *******************************************************************************
  4. * Written by Gershon Elber, Sep. 91.                          *
  5. ******************************************************************************/
  6.  
  7. #include "cagd_loc.h"
  8.  
  9. /*****************************************************************************
  10. * DESCRIPTION:                                                               M
  11. * Provides the way to modify/get a single control point into/from the curve. M
  12. *                                                                            *
  13. * PARAMETERS:                                                                M
  14. *   Crv:        Curve to be modified/query.                                  M
  15. *   CtlPt:      New control point to be substituted into Crv. Must carry the M
  16. *               same PType as Crv if to be written to Crv.                   M
  17. *   Index:      In curve CRV's control polygon to substitute/query CtlPt.    M
  18. *   Write:      If TRUE CtlPt is copied into Crv, if FALSE the point is      M
  19. *               copied from Crv to CtlPt.                     M
  20. *                                                                            *
  21. * RETURN VALUE:                                                              M
  22. *   CagdCrvStruct *: If Write is TRUE, the new modified curve, if WRITE is   M
  23. *                    FALSE, NULL.                                            M
  24. *                                                                            *
  25. * KEYWORDS:                                                                  M
  26. *   CagdEditSingleCrvPt, curve editing                                       M
  27. *****************************************************************************/
  28. CagdCrvStruct *CagdEditSingleCrvPt(CagdCrvStruct *Crv,
  29.                    CagdCtlPtStruct *CtlPt,
  30.                    int Index,
  31.                    CagdBType Write)
  32. {
  33.     CagdBType
  34.     IsNotRational = !CAGD_IS_RATIONAL_CRV(Crv);
  35.     int i,
  36.     Length = Crv -> Length,
  37.     MaxCoord = CAGD_NUM_OF_PT_COORD(Crv -> PType);
  38.     CagdCrvStruct
  39.     *NewCrv = Write ? CagdCrvCopy(Crv) : NULL;
  40.     CagdRType
  41.     **Points = Write ? NewCrv -> Points : Crv -> Points;
  42.  
  43.     if (Index < 0 || Index >= Length)
  44.     CAGD_FATAL_ERROR(CAGD_ERR_INDEX_NOT_IN_MESH);
  45.  
  46.     if (Write) {
  47.     if (Crv -> PType != CtlPt -> PtType)
  48.         CAGD_FATAL_ERROR(CAGD_ERR_PT_OR_LEN_MISMATCH);
  49.  
  50.     for (i = IsNotRational; i <= MaxCoord; i++)
  51.         Points[i][Index] = CtlPt -> Coords[i];
  52.     }
  53.     else {
  54.         CtlPt -> PtType = Crv -> PType;
  55.  
  56.     for (i = IsNotRational; i <= MaxCoord; i++)
  57.         CtlPt -> Coords[i] = Points[i][Index];
  58.     }
  59.  
  60.     return NewCrv;
  61. }
  62.  
  63. /*****************************************************************************
  64. * DESCRIPTION:                                                               M
  65. * Provides the way to modify/get a single control point into/from a surface. M
  66. *                                                                            *
  67. * PARAMETERS:                                                                M
  68. *   Srf:        Surface to be modified/query.                                M
  69. *   CtlPt:      New control point to be substituted into Srf. Must carry the M
  70. *               same PType as Srf if to be written to Srf.                   M
  71. *   UIndex, VIndex: In surface Srf's control mesh to substitute/query CtlPt. M
  72. *   Write:      If TRUE CtlPt is copied into Srf, if FALSE the point is      M
  73. *               copied from Srf to CtlPt.                     M
  74. *                                                                            *
  75. * RETURN VALUE:                                                              M
  76. *   CagdCrvStruct *: If Write is TRUE, the new modified curve, if WRITE is   M
  77. *                    FALSE, NULL.                                            M
  78. *                                                                            *
  79. * KEYWORDS:                                                                  M
  80. *   CagdEditSingleSrfPt, surface editing                                     M
  81. *****************************************************************************/
  82. CagdSrfStruct *CagdEditSingleSrfPt(CagdSrfStruct *Srf,
  83.                    CagdCtlPtStruct *CtlPt,
  84.                    int UIndex,
  85.                    int VIndex,
  86.                    CagdBType Write)
  87. {
  88.     CagdBType
  89.     IsNotRational = !CAGD_IS_RATIONAL_SRF(Srf);
  90.     int i,
  91.     ULength = Srf -> ULength,
  92.     VLength = Srf -> VLength,
  93.     MaxCoord = CAGD_NUM_OF_PT_COORD(Srf -> PType);
  94.     CagdSrfStruct
  95.     *NewSrf = Write ? CagdSrfCopy(Srf) : NULL;
  96.     CagdRType
  97.     **Points = Write ? NewSrf -> Points : Srf -> Points;
  98.  
  99.     if (UIndex < 0 || UIndex >= ULength ||
  100.     VIndex < 0 || VIndex >= VLength)
  101.     CAGD_FATAL_ERROR(CAGD_ERR_INDEX_NOT_IN_MESH);
  102.  
  103.     if (Write) {
  104.     if (Srf -> PType != CtlPt -> PtType)
  105.         CAGD_FATAL_ERROR(CAGD_ERR_PT_OR_LEN_MISMATCH);
  106.  
  107.     for (i = IsNotRational; i <= MaxCoord; i++)
  108.         Points[i][CAGD_MESH_UV(NewSrf, UIndex, VIndex)] =
  109.         CtlPt -> Coords[i];
  110.     }
  111.     else {
  112.         CtlPt -> PtType = Srf -> PType;
  113.  
  114.     for (i = IsNotRational; i <= MaxCoord; i++)
  115.         CtlPt -> Coords[i] =
  116.         Points[i][CAGD_MESH_UV(Srf, UIndex, VIndex)];
  117.     }
  118.  
  119.     return NewSrf;
  120. }
  121.